﻿namespace MefContrib.Models.Provider.Tests
{
    using System;
    using System.Collections.Generic;
    using NUnit.Framework;

    [TestFixture]
    public class ProviderExportDefinitionTests
    {
        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowExceptionIfMemberParameterIsNull()
        {
            ProviderExportDefinition export =
                new ProviderExportDefinition(null, null, null);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowExceptionIfContractNameIsNull()
        {
            ProviderExportDefinition export =
                new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), null, null);
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void ConstructorShouldThrowExceptionIfContractNameIsEmpty()
        {
            ProviderExportDefinition export =
                new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), string.Empty, null);
        }

        [Test]
        public void ContractNameShouldReturnValuePassedInConstructor()
        {
            ProviderExportDefinition export =
                new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), "contract", null);

            Assert.AreEqual(export.ContractName, "contract");
        }

        [Test]
        public void MetadataShouldNotBeNullWhenPassedInConstructor()
        {
            Dictionary<string, object> metadata =
                new Dictionary<string, object> { { "Foo", 0 }, { "Bar", 1 } };

            ProviderExportDefinition export =
                new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), "contract", metadata);

            Assert.IsNotNull(export.Metadata);
        }

        [Test]
        public void MemberShouldReturnValuePassedInConstructor()
        {
            Type member =
                typeof(ProviderExportDefinitionTests);

            ProviderExportDefinition export =
                new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), "contract", null);

            Assert.AreEqual(export.Member, member);
        }
    }
}